layui.use(['form', 'layer'], function () {
    var form = layui.form
    layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;
    form.on("submit(editEducationType)", function (data) {
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候', { icon: 16, time: false, shade: 0.8 });
        const { educationtype_id: id, educationtype_name: name, addOrUpdate } = data.field;
        var educationType = {
            id,
            name
        }
        if (addOrUpdate == 0) {//添加
            $.ajax({
                url: baseUrl + "educationType/addEducationType.php",
                data: educationType,
                type: "POST",
                dataType: "text",
                success: function (data) {
                    if (data == "1") {
                        message(index, '添加学历类型成功！')
                    } else {
                        message(index, '添加学历类型失败！')
                    }
                }
            })
        } else {//修改
            $.ajax({
                url: baseUrl + "educationType/updateEducationType.php",
                data: educationType,
                type: "POST",
                dataType: "text",
                success: function (data) {
                    if (data == "1") {
                        message(index, '修改学历类型成功！')
                    } else {
                        message(index, '修改学历类型失败！')
                    }
                }
            })
        }
        return false;
    })
    function message(index, msg) {
        setTimeout(function () {
            top.layer.close(index);
            top.layer.msg(msg);
            parent.layer.closeAll("iframe");
            //父页面表格重载
            parent.layui.table.reload("educationTypeListTable");
        }, 1000);
    }
})